package com.ruoyi.register.controller;


import com.ruoyi.register.entity.VideoEntity;
import com.ruoyi.register.service.MerchantRegisterService;
import com.ruoyi.register.vo.GoodsVo;
import com.ruoyi.register.vo.MerchantUserVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import sun.net.httpserver.AuthFilter;
import utils.FileUploadTool;
import utils.JsoupUtils;
import utils.Result;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: 程昱轩
 * @Description: TODO
 * @DateTime: @date 2023/2/23 14:31
 **/
@RestController
@RequestMapping("/register")
public class MerchantRegisterController {
    private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
    @Resource
    private MerchantRegisterService merchantRegisterService;

    @RequestMapping("/merchantRegister")
    public Result register(@RequestBody MerchantUserVo merchantUserVo){

        return merchantRegisterService.merchantRegister(merchantUserVo);
    }
    @RequestMapping("/test")
    public void test(){
        int a=2;
        log.info("1111111{}",a );
        System.out.println("我执行了-------------------");
    }
    @RequestMapping("/parseJd")
    public Result parseJd() throws Exception {
        List<GoodsVo> list = JsoupUtils.parsejd("");

        return merchantRegisterService.importData(list);

    }
    @RequestMapping("/uploadVideo")
    public Result uploadVideo(@RequestParam(value = "file", required = false) MultipartFile file,
                              HttpServletRequest request) {
        log.info("视频转码成功");
        VideoEntity videoEntity = new VideoEntity();
        String logoPathDir = request.getParameter("url");
        FileUploadTool fileUploadTool = new FileUploadTool();
        videoEntity = fileUploadTool.createFile(logoPathDir, file, request);
        if (videoEntity==null){
            return Result.error(4001,"文件上传失败");
        }

        return Result.success(videoEntity);
    }

}
